﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace YbService.Entity
{
    public class CardFormat
    {
        /// <summary>
        /// 卡的识别码
        /// </summary>
        public string KaShiBieMa { set; get; }

        /// <summary>
        /// 参保地区行政区划代码
        /// </summary>
        public string CanBaoDiXzqhdm { set; get; }

        /// <summary>
        /// 卡类别
        /// </summary>
        public string KaLeiBie { set; get; }
        
        /// <summary>
        /// 卡号
        /// </summary>
        public string KaHao { set; get; }

        /// <summary>
        /// 公民身份号码
        /// </summary>
        public string ShenFenZh { set; get; }
        
        /// <summary>
        /// 姓名
        /// </summary>
        public string XingMing { set; get; }

        /// <summary>
        /// 性别
        /// </summary>
        public string XingBie { set; get; }

        /// <summary>
        /// 读卡机具型号
        /// </summary>
        public string DuKaQiXh { set; get; }

        /// <summary>
        /// 读卡机序列号
        /// </summary>
        public string DuKaQiXlh { set; get; }

        /// <summary>
        /// DLL版本
        /// </summary>
        public string DllBb { set; get; }

        /// <summary>
        /// Lib版本
        /// </summary>
        public string LibBb { set; get; }

        /// <summary>
        /// PSAM卡号_终端机编号
        /// </summary>
        public string PsamKaHaoZdjbh { set; get; }

        /// <summary>
        /// 渠道代码
        /// </summary>
        public string QuDaoDaiMa { set; get; }

        /// <summary>
        /// 二维码ID
        /// </summary>
        public string ErWeiMaId { set; get; }

        /// <summary>
        /// 支付宝用户编号
        /// </summary>
        public string ZhiFuBaoYhbh { set; get; }

        /// <summary>
        /// 电子凭证信息
        /// </summary>
        public DzpzInfo DianZiPzxx { set; get; }


        #region 健康卡信息

        /// <summary>
        /// 健康卡地址
        /// </summary>
        public string JianKangKaDz { set; get; }
        /// <summary>
        /// 联系电话
        /// </summary>
        public string JianKangKaLxdh { set; get; }
        #endregion

        /// <summary>
        /// 读卡类型
        /// </summary>
        public string ReadType { set; get; }

        /// <summary>
        /// 返回的字符串
        /// </summary>
        private string OutPutStr { set; get; }

        private string _SplitStr = "|";

        public CardFormat()
        {

        }

        public CardFormat(CardFormat cardFormat)
        {
            KaShiBieMa = cardFormat.KaShiBieMa;
            CanBaoDiXzqhdm = cardFormat.CanBaoDiXzqhdm;
            KaLeiBie = cardFormat.KaLeiBie;
            KaHao = cardFormat.KaHao;
            ShenFenZh = cardFormat.ShenFenZh;
            XingMing = cardFormat.XingMing;
            XingBie = cardFormat.XingBie;
            DuKaQiXh = cardFormat.DuKaQiXh;
            DuKaQiXlh = cardFormat.DuKaQiXlh;
            DllBb = cardFormat.DllBb;
            LibBb = cardFormat.LibBb;
            PsamKaHaoZdjbh = cardFormat.PsamKaHaoZdjbh;
            QuDaoDaiMa = cardFormat.QuDaoDaiMa;
            ErWeiMaId = cardFormat.ErWeiMaId;
            ZhiFuBaoYhbh = cardFormat.ZhiFuBaoYhbh;
            JianKangKaDz = cardFormat.JianKangKaDz;
            JianKangKaLxdh = cardFormat.JianKangKaLxdh;
            ReadType = cardFormat.ReadType;
            OutPutStr = cardFormat.OutPutStr;
            DianZiPzxx = cardFormat.DianZiPzxx;
        }

        public CardFormat(string outPutStr)
        {
            OutPutStr = outPutStr.Replace("\u0000", "");
            try
            {
                string[] s = OutPutStr.Split(new string[] { _SplitStr }, StringSplitOptions.None);
                int p = 0;
                KaShiBieMa = s[p++];
                CanBaoDiXzqhdm = KaShiBieMa.Length > 6 ? KaShiBieMa.Substring(0, 6) : string.Empty;
                KaLeiBie = s[p++];
                KaHao = s[p++];
                ShenFenZh = s[p++];
                XingMing = s[p++];
                XingBie = s[p++];
                DuKaQiXh = s[p++];
                DuKaQiXlh = s[p++];
                DllBb = s[p++];
                LibBb = s[p++];
                PsamKaHaoZdjbh = s[p++];
                QuDaoDaiMa = p < s.Length ? s[p++] : string.Empty;
                ErWeiMaId = p < s.Length ? s[p++] : string.Empty;
                ZhiFuBaoYhbh = p < s.Length ? s[p++] : string.Empty;
            }
            catch (Exception ee)
            {
                Exception ex = new Exception("分解市民卡返回串错误[" + outPutStr + "]", ee);
                throw ex;
            }
        }

    }
}
